package com.quectel.sdk.kuangshi;

import com.quectel.sdk.ex.hikisc.HikFactoryErrorException;

/**
 * 海康实例建造器
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2022-10-19 11:01:00
 */
public class KsClientBuilder {

    /**
     * 盒子地址
     */
    private String baseUrl;
    /**
     * 账号
     */
    private String username;
    /**
     * 密码
     */
    private String password;

    private KsClientBuilder() {
    }

    public static KsClientBuilder builder() {
        return new KsClientBuilder();
    }

    public KsClientBuilder baseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
        return this;
    }

    public KsClientBuilder username(String username) {
        this.username = username;
        return this;
    }

    public KsClientBuilder password(String password) {
        this.password = password;
        return this;
    }

    public <T extends AbstractKsBaseClient> T build(Class<T> executorCls) {
        if (baseUrl == null || username == null || password == null) {
            throw new HikFactoryErrorException("Missing request parameter.");
        }
        try {
            T t = executorCls.newInstance();
            t.setRequester(ksRequester.getInstance(baseUrl, username, password));
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
